package com.ruoyi.common.enums;

import java.util.Objects;

/**
 * @author 异常
 */
public enum ExceptionEnum implements IIntegerEnum{
    USER_NOT_LOGIN(100001, "用户未登录"),
    USER_NOT_EXISTS(100002, "用户不存在"),
    USER_DISABLED(100003, "用户被禁用"),
    TOKEN_EXPIRED(100004, "用户登录已过期"),
    TOKEN_ERROR(100005, "用户校验未通过"),
    OPENID_ERROR(100006, "用户openid错误"),

    ;

    private Integer code;
    private String msg;

    ExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public static ExceptionEnum getByCode(int code, ExceptionEnum[] values) {
        for (ExceptionEnum value : values) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
